$(function() {
	initBlockUI();
	updateTable(0, "#pager");
	initPagination();
});

// 初始化分页
function initPagination()
{
	$("#pager").pagination($("#wholepage").val(), {
		items_per_page: 10,
		prev_text: "前一页",
		next_text: "后一页",
		callback: updateTable
	});
}

// 更新表格中的数据
function updateTable(page, pager_block)
{
   var url = "wait_for_examining.php";
   var pars = { "page_status": 1, "page": (page + 1) };
   $.post(url, pars, function(xmlobj){
	  $("#tbody2").html("");
	  $(xmlobj).find("item").each(function(i){
		 var docid = $(this).find("doc_id").text();
		 var class_name = $(this).find("class_name").text();
		 var tpl_name = $(this).find("tpl_name").text();
		 var title = $(this).find("title").text();
		 var username = $(this).find("username").text();
		 var instancy = $(this).find("instancy").text();
		 var applytime = $(this).find("apply_time").text();
		 var ismulti = $(this).find("is_multi").text();
		 var issent = $(this).find("is_sent").text();
		 var iscanceled = $(this).find("is_canceled").text();
		 var isfinished = $(this).find("is_finished").text();
		 var ispassed = $(this).find("is_passed").text();
		 $("<tr></tr>")
		   .append($("<th></th>").html((i + 1)))
		   .append($("<td></td>").html(class_name + " -&gt; " + tpl_name))
		   .append($("<td></td>").html($("<a href=\"#\"></a>")
									   .attr("docid", docid)
									   .html(title)
									   .click(function(){
										  openExam($(this).attr("docid"));
										  return false;
									   })
									   ))
		   .append($("<td></td>").html(username))
		   .append($("<td></td>").html(getIns(instancy)))
		   .append($("<td></td>").html(applytime))
		   .append($("<td></td>").html(getDocStatusBlock(ismulti, 0)
		   								+ getDocStatusBlock(issent, 1)
		   								+ getDocStatusBlock(iscanceled, 2)
		   								+ getDocStatusBlock(isfinished, 3)
		   								+ getDocStatusBlock(ispassed, 4)
		   								+ "<br />"))
		 .appendTo("#tbody2");
	  });
	  tablePretty("#tbody2");
	  $("a.doc_status_tip0, a.doc_status_tip1").tooltip({
	  	delay: 0,
	  	showURL: false,
	  	bodyHandler: function() { return $("<div></div>").html($(this).attr("linktitle")) }
	  });
   });
	return false;
}

// 获取紧急程度
function getIns(instancy)
{
   var str = "";
   switch (instancy)
	 {
	  case 1:
		str = "一般";
		break;
	  case 2:
		str = "紧急";
		break;
	  case 3:
		str = "加急";
		break;
	  default:
		str = "一般";
	 }
   return str;
}

// 打开审批页面
function openExam(doc_id)
{
   window.open("wf_examin.php?doc_id=" + doc_id, "待审批", "toolbar=no,menubar=no,width=820,height=600,top=50,left=100,resizable=yes");
}
